import jsonpath
import time

from functools import wraps

data = {
    "result": 'true',
    "code": 200,
    "message": "获取成功",
    "datas": {
        "online_kgts": [
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "D"
                        ],
                        "opt_count": 4,
                        "opt_type": "单选",
                        "order_index": 0,
                        "que_info": 'null',
                        "que_name": "单选1",
                        "que_no": "06001",
                        "que_score": 5.00,
                        "que_type": "选择题"
                    }
                ],
                "order_index": 0,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "C"
                        ],
                        "opt_count": 4,
                        "opt_type": "单选",
                        "order_index": 1,
                        "que_info": 'null',
                        "que_name": "单选2",
                        "que_no": "06001",
                        "que_score": 5.00,
                        "que_type": "选择题"
                    }
                ],
                "order_index": 1,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [],
                        "opt_count": 4,
                        "opt_type": "单选",
                        "order_index": 2,
                        "que_info": 'null',
                        "que_name": "单选3",
                        "que_no": "06001",
                        "que_score": 5.00,
                        "que_type": "选择题"
                    }
                ],
                "order_index": 2,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [],
                        "opt_count": 4,
                        "opt_type": "单选",
                        "order_index": 3,
                        "que_info": 'null',
                        "que_name": "单选4",
                        "que_no": "06001",
                        "que_score": 5.00,
                        "que_type": "选择题"
                    }
                ],
                "order_index": 3,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "B"
                        ],
                        "opt_count": 4,
                        "opt_type": "单选",
                        "order_index": 4,
                        "que_info": 'null',
                        "que_name": "单选5",
                        "que_no": "06001",
                        "que_score": 5.00,
                        "que_type": "选择题"
                    }
                ],
                "order_index": 4,
                "is_choic_que": 'false'
            }
        ],
        "online_zgts": [
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "https://wuyue-test.oss-cn-beijing.aliyuncs.com/[101255]在线考试压测/语文/WY03/1018282192_07001_up_0.jpg"
                        ],
                        "opt_count": 1,
                        "opt_type": "1",
                        "que_info": 'null',
                        "que_name": "短",
                        "que_no": "07001",
                        "que_score": 10.00,
                        "que_type": "解答题",
                        "order_index": 1
                    }
                ],
                "order_index": 1,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "https://wuyue-test.oss-cn-beijing.aliyuncs.com/[101255]在线考试压测/语文/WY03/1018282192_07002_up_0.jpg"
                        ],
                        "opt_count": 1,
                        "opt_type": "1",
                        "que_info": 'null',
                        "que_name": "长",
                        "que_no": "07002",
                        "que_score": 10.00,
                        "que_type": "解答题",
                        "order_index": 2
                    }
                ],
                "order_index": 2,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            ""
                        ],
                        "opt_count": 1,
                        "opt_type": "1",
                        "que_info": 'null',
                        "que_name": "拼接",
                        "que_no": "07003",
                        "que_score": 10.00,
                        "que_type": "解答题",
                        "order_index": 3
                    }
                ],
                "order_index": 3,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            "https://wuyue-test.oss-cn-beijing.aliyuncs.com/[101255]在线考试压测/语文/WY03/1018282192_07005_up_0.jpg"
                        ],
                        "opt_count": 1,
                        "opt_type": "1",
                        "que_info": 'null',
                        "que_name": "中",
                        "que_no": "07005",
                        "que_score": 10.00,
                        "que_type": "解答题",
                        "order_index": 5
                    }
                ],
                "order_index": 5,
                "is_choic_que": 'false'
            },
            {
                "que_list": [
                    {
                        "stu_answer": [
                            ""
                        ],
                        "opt_count": 1,
                        "opt_type": "1",
                        "que_info": 'null',
                        "que_name": "整页",
                        "que_no": "07006",
                        "que_score": 10.00,
                        "que_type": "解答题",
                        "order_index": 6
                    }
                ],
                "order_index": 6,
                "is_choic_que": 'false'
            }
        ],
        "systemtime": "1668416691895"
    }
}


def fun_out(flag):
    def fun(fun_time):
        # @wraps(fun_time)
        def exc(*args, **kwargs):
            if flag:
                st_time = time.time()
                fun = fun_time(*args, **kwargs)
                print('程序运行的时间：{}'.format(time.time() - st_time))
                return fun
            else:
                fun = fun_time(*args, **kwargs)
                return fun

        return exc

    return fun


li = ['message', 'code']

FLAGE = True


@fun_out(FLAGE)
def fun_json0(a):
    message = jsonpath.jsonpath(data, '$..{}'.format(a[0]))
    time.sleep(2)
    code = jsonpath.jsonpath(data, '$..{}'.format(a[1]))
    print('message = {0};code = {1}'.format(message, code))
    return 'fun2 over'


FLAGE = False


@fun_out(FLAGE)
def fun_json1(a):
    message = jsonpath.jsonpath(data, '$..{}'.format(a[0]))
    time.sleep(2)
    '''
    这是一个注释内容：
        1.这是第一行
        2.这是第二行
    '''
    code = jsonpath.jsonpath(data, '$..{}'.format(a[1]))
    print('message = {0};code = {1}'.format(message, code))
    return 'fun2 over'


fun_json0(li)
fun_json1(li)


def timer(func):
    def inner(*args, **kwargs):
        start = time.time()
        re = func(*args, **kwargs)
        print(time.time() - start)
        return re

    return inner


@timer
def func2(a):
    # print('in func2 and get a:%s' % (a))
    print(a)
    # return 'fun2 over'

# func2('aaaaaa')
# print(func2('aaaaaa'))
